<?php
//UI
function matchSubNavName($subnavHref)
{
	$tables = array();
	$tables[0] = 'extras_subnavigation';
	
	$fields = array();
	$fields[0] = 'name';
	
	$whereClause = 'href LIKE "'.$subnavHref.'"';
	
	$data = SQLRecover($tables, $fields, $whereClause);
	
	if($data['queryStatus'] == 'DB Query success!')
	{
		return $data['name'][0];
	}
	
	return $subnavHref;
}

function matchSubNavHref($subnavName)
{
	$tables = array();
	$tables[0] = 'extras_subnavigation';
	
	$fields = array();
	$fields[0] = 'href';
	
	$whereClause = 'name LIKE "'.$subnavName.'"';
	
	$data = SQLRecover($tables, $fields, $whereClause);
	
	if($data['queryStatus'] == 'DB Query success!')
	{
		return $data['href'][0];
	}
	
	return $subnavName;
}
///---
function userAgent()
{
	return $_SERVER['HTTP_USER_AGENT'];
}

function userEngine($engine)
{
	$test = stristr(userAgent(), $engine);
	if($test == '')
	{
		return false;
	}
	else
	{
		return true;
	}
}
function post($name)
{
	if (isset($_POST[$name]))
	{
		return $_POST[$name];
	}
	else
	{
		return 'null';
	}
}

function frmFile($name)
{
	if (isset($_FILES[$name]))
	{
		return $_FILES[$name];
	}
	else
	{
		return 'null';
	}
}

function get($name)
{
	if (isset($_GET[$name]))
	{
		return $_GET[$name];
	}
	else
	{
		return 'null';
	}
}

function session($name)
{
	if (isset($_SESSION[$name]))
	{
		return $_SESSION[$name];
	}
	else
	{
		return 'null';
	}
}

function queryString()
{
	return $_SERVER['QUERY_STRING'];
}

function unsetVar($type, $name)
{
	if ($type == 'POST')
	{
		if (post($name) != 'null')
		{
			unset($_POST[$name]);
			return true;
		}
		else
		{
			return false;
		}

	}
	else if ($type == 'GET')
	{
		if (get($name) != 'null')
		{
			unset($_GET[$name]);
			return true;
		}
		else
		{
			return false;
		}
	}
	else if ($type == 'SESSION')
	{
		if (session($name) != 'null')
		{
			unset($_SESSION[$name]);
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return false;
	}
	
}

function setSession($name, $value, $overwrite)
{
	if (session($name) != 'null')
	{
		if ($overwrite == true)
		{
			$_SESSION[$name] = $value;
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		$_SESSION[$name] = $value;
		return true;
	}
}

function areAllFilledUp($getPost, $cmdVarArray)
{
	if ($getPost == 'GET')
	{
		$yesNo = true;
		for($i=0; $i<sizeOf($cmdVarArray); $i++)
		{
			if (get($cmdVarArray[$i]) == 'null' || get($cmdVarArray[$i]) == '')
			{
				$yesNo = false;
			}
		}
		return $yesNo;
	}
	else if ($getPost == 'POST')
	{
		$yesNo = true;
		$checker = 'true';
		for($i=0; $i<sizeOf($cmdVarArray); $i++)
		{
			if (post($cmdVarArray[$i]) == 'null' || post($cmdVarArray[$i]) == '' )
			{
				$yesNo = false;
				$checker = 'false';
			}
		}
		return $yesNo;
	}
	else
	{
		return false;
	}
}

function displayOnlyIf($cmdVarType, $cmdVarName, $cmdVarValue, $content)
{
	if($cmdVarType == 'POST')
	{
		if (post($cmdVarName) == $cmdVarValue)
		{
			return $content;
		}
		else
		{
			//doNothing();
			return '';
		}
	}
	else if($cmdVarType == 'GET')
	{
		if (get($cmdVarName) == $cmdVarValue)
		{
			return $content;
		}
		else
		{
			//doNothing();
			return '';
		}
	}
	else if($cmdVarType == 'SESSION')
	{
		if (session($cmdVarName) == $cmdVarValue)
		{
			return $content;
		}
		else
		{
			//doNothing();
			return '';
		}
	}
	else
	{
		//doNothing();
		return '';
	}
}
?>